package DBLayer;

import ModelLayer.Customer;
import ModelLayer.Offer;
import org.junit.Test;

import java.util.ArrayList;

import static org.junit.Assert.fail;

public class DBOfferTest {

    @Test
    public void testGetAllOffers() throws Exception {
        ArrayList<Offer> offerList = new ArrayList<Offer>();
        DBOffer dbOff = new DBOffer();
        offerList = dbOff.getAllOffers();

        if (offerList != null){
            for (Offer off1 : offerList)
                System.out.println("idOffer " + off1.getIdOffer() + "calculatedPrice " + off1.getCalculatedPrice() + "discount " + off1.getDiscount());
        }
        else fail();
    }

    @Test
    public void testFindOfferId() throws Exception {
        DBOffer dbOff = new DBOffer();
        Offer off = dbOff.findOfferId("267");

       if (off != null){
           System.out.println("OfferId has been found");
           System.out.println("idOffer : " + off.getIdOffer() + ", offerStatus : " + off.getStatusOffer());
           }
        else fail();
    }

    @Test
    public void testInsertOffer() throws Exception {
        Offer off = new Offer();

        String idCustomer = "7777";

        off.setIdOffer("nextIdOffer");
        off.setCustomer(new Customer(idCustomer));
        off.setCalculatedPrice(200.00);
        off.setDateStart("12122012");
        off.setDateEnd("14122012");
        off.setAcceptDeadline("12122012");
        off.setDiscount(20);
        off.setStatusOffer("Active");
        off.setSentDate("12122012");
        off.setPricePerHour(40);

        DBOffer dbOff = new DBOffer();
        int i = dbOff.insertOffer(off);

        if(i == 1){
            System.out.println("Added");
        }
        else fail();
    }

    @Test
    public void testUpdateOffer() throws Exception {
        Offer off = new Offer();
        DBOffer dbOff = new DBOffer();
        off = dbOff.findOfferId("267");
        off.setDiscount(3500);

        int i = dbOff.updateOffer(off);
    }


    @Test
    public void testDeleteOffer() throws Exception {
        Offer off = new Offer();
        DBOffer dbOff = new DBOffer();
        off = dbOff.findOfferId("268");

        if (off != null){
            int i = dbOff.deleteOffer("268");

        }
        else fail();
    }
}